<template>
	<view :class="currentTheme">
		<a-nabbar :name="option.label" />
		<mescroll-body ref="mescrollRef" @init="mescrollInit"  @up="upCallback" @down="downCallback">
			<view class="u-padding-left-32 u-padding-right-32 u-padding-top-20" v-for="(item,index) in dataList" :key="index" >
				<item-box padding="20">
					<reply-item
						:item="item" 
						:showSinglaChat="option.btnType==='showSinglaChat'"
						@removeItem="removeItem"
						 :showProductName="option.type=='experienceProduct'?false:true"
						:showDelete="option.btnType==='showDelete'"></reply-item>
				</item-box>
			</view>
		</mescroll-body>
		<model v-model="removeFlag" :show-title="false" show-cancel-button  cancel-color="#333333" :confirm-color="currentThemeObj.primary" @confirm="removeItemList" content="是否删除评测？" />
	</view>
</template>

<script>
	import replyItem from '@/components/replyItem/replyItem.vue'
	import upCallback from '@/mixins/upCallbackMixin.js'
	import model from '@/components/u-modal/u-modal.vue'
	import {deleteIds} from '@/api/crud.js'
	export default {
		mixins:[upCallback],
		data() {
			return {
				dataList:[],
				option:{
					label:'评测管理'
				},
				form:{},
				removeFlag:false,
				removeItemObj:{},
				name:'',
				apiModule:'',
				apiType:''
			}
		},
		components: {
			replyItem,model
		},
		onLoad(option) {
			this.option = option;
			if(option.id) this.form.productId = option.id
			switch (option.type){
				case 'detailTestReply': //剧本评测 仅查看
					this.apiModule = 'shopApi'
					this.apiType = 'exhibitProductComment'
					this.name = 'getSystemStoreProductComments'
					this.form.uid=null
					break;
				case 'myTestReply': //我的评测
					this.apiModule = 'shopApi'
					this.apiType = 'exhibitProductComment'
					this.name = 'getSystemStoreProductComments'
					break;
				case 'goodsReply': //商城剧本评价 
					this.apiModule = 'shopApi'
					this.apiType = 'storeProductReply'
					this.name = ''
					if(option.id) this.form.uid = '' //剧本详情查看更多 根据productid查询
					break;
				case 'issueManager':  //发行评测管理
					this.apiModule = 'shopApi'
					this.apiType = 'exhibitProductComment'
					this.name = 'getCommentsByUid'
					//this.form.exhibitId = null
					break;
				case 'game':  //组局剧本评价
					this.apiModule = 'shopApi'
					this.apiType = 'systemStoreProductComment'
					this.name = 'getSystemStoreProductComments'
					break;
				case 'store':  //店家评价
					this.apiModule = 'shopApi'
					this.apiType = 'systemStoreComment'
					this.name = 'getSystemStoreComments'
					this.form.storeId = option.storeId
					break;
				case 'DM':  //DM评价
					this.apiModule = 'shopApi'
					this.apiType = 'systemStoreUserComment'
					this.name = 'getSystemStoreUserComments'
					this.form.dmUid = option.dmUid
					break;
				case 'experienceProduct':  //体验商城剧本评价
					this.apiModule = 'shopApi'
					this.apiType = 'storeProductReply'
					this.name = 'queryExperienceReplys'
					this.form.uid=null
					break;
			}
		},
		methods: {
			removeItem(item) {
				this.removeFlag = true;
				this.removeItemObj = item;
			},
			removeItemList(){
				deleteIds('','exhibitProductComment',this.apiModule,this.removeItemObj.id).then(res=>{
					const index = this.dataList.findIndex(val=>val.id===this.removeItemObj.id);
					if(index>-1) this.dataList.splice(index,1)
					this.$u.toast('删除成功')
					if(this.dataList.length===0){
						this.mescroll.resetUpScroll()
					}
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	
</style>
